package week_three_day03_HttpServer;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class MySever {
	public static void main(String[] args) throws Exception{
		ServerSocket server=new ServerSocket(9000);
		Socket sk=server.accept();
		BufferedReader reader=new BufferedReader(new InputStreamReader(sk.getInputStream()));
		OutputStream out=sk.getOutputStream();
		String line=null;
		while((line=reader.readLine()).trim().length()!=0){
			System.out.println(line);
		}
		System.out.println("header end....");
//		char[] buf=new char[17];
//		int len=reader.read(buf);
//		String requestBody=new String(buf,0,len);
//		System.out.println(requestBody);
		
		Document dom=new Document();
		
		Element root=new Element("html");
		Element body=new Element("body");
		Element button=new Element("button");
		button.setText("find");
		body.addContent(button);
		root.addContent(body);
		dom.setRootElement(root);
		
		XMLOutputter ot1=new XMLOutputter();
		out.write("HTTP/1.1 200 OK\r\n\r\n".getBytes());
		ot1.output(root, out);
		out.close();
		reader.close();
		sk.close();
		server.close();
	}
}
